var hash=[];

var test=function(num, tmphash) {
    var tmp=num, tmp1, tmp2;
    tmphash = tmphash || [];
    do{
        tmp1 = tmp % 10;
        if(tmphash[tmp1]) return false;
        tmphash[tmp1] = 1;
        tmp = (tmp-tmp1)/10;
        if(tmp1==0 && tmp !=0) return false;
    }while(tmp>0);
    return true;
}

for(var i=2; i<=9; i++) {
    for(var j=1000; j<=9999; j++) {
        var tmphash=[];
        if(!test(i, tmphash)) continue;
        if(!test(j, tmphash)) continue;
        var tmp = i*j;
        if(tmp>=10000) break;
        if(!test(tmp, tmphash)) continue;
        hash[tmp] = 1;
        print("find ... " + tmp + "," + i + "," +j);
    }
}

for(var i=10; i<=99; i++) {
    if(test(i)) {
        for(var j=100; j<=999; j++) {
            var tmphash=[];
            if(!test(i, tmphash)) continue;
            if(!test(j, tmphash)) continue;
            var tmp = i*j;
            if(tmp>=10000) break;
            if(!test(tmp, tmphash)) continue;
            hash[tmp] = 1;
            print("find ... " + tmp + "," + i + "," +j);
        }
    }
}
var sum=0;
for(var i=0; i<hash.length; i++) {
    if(hash[i]) {
        sum+=i;
    }
}
print("sum=" + sum);
